package intro.databases.gtCarRental.ui.employee;

import intro.databases.gtCarRental.GTCRActivity;
import intro.databases.gtCarRental.R;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

public class Employee_Home extends GTCRActivity {
	Spinner reports;
	RadioButton reportButton;
	
	@Override
	public void onCreate(Bundle b) {
		super.onCreate(b);
		setContentView(R.layout.employee_home);
		
		reports = (Spinner) findViewById(R.id.spinner_employeeHome_reports);
		reportButton = (RadioButton) findViewById(R.id.radioButton_employeeHome_viewReports);
		
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.employee_reports, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		reports.setAdapter(adapter);
		reports.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				reportButton.setChecked(true);
			}
			@Override
			public void onNothingSelected(AdapterView<?> arg0) {}
		});
	}
	
	public void next(View v) {
		RadioGroup group = (RadioGroup) findViewById(R.id.radioGroup_employeeHome_options);
		Class<?> next = null;
		switch(group.getCheckedRadioButtonId()) {
			case R.id.radioButton_employeeHome_manageCars:
				next = ManageCars.class;
				break;
			case R.id.radioButton_employeeHome_maintenanceRequest:
				next = MaintenanceRequests.class;
				break;
			case R.id.radioButton_employeeHome_rentalChangeRequest:
				next = RentalChangeRequest.class;
				break;
			case R.id.radioButton_employeeHome_viewReports:
				startReportActivity();
				return;
		}
		Intent intent = new Intent(this, next);
		startActivity(intent);		
	}

	private void startReportActivity() {
		Class<?> next = null;
		
		String report = ((TextView) reports.getSelectedView()).getText().toString();
		if(report.equals("Location Preference Report")) {
			next = LocationPreferenceReport.class;
		} else if(report.equals("Frequent Users Report")) {
			next = FrequentUsersReport.class;
		} else {
			next = MaintenanceHistoryReport.class;
		}
		
		Intent intent = new Intent(this, next);
		startActivity(intent);	
	}
}
